package org.nicocube.airain.gwt.client.ui;

import org.nicocube.airain.gwt.client.AirainWeb;

import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;

public abstract class AirainPanel {
	private AirainWeb aw;
	public AirainPanel(AirainWeb aw) {
		this.aw = aw;
	}
	public AirainWeb getAW() {
		return aw;
	}
	public abstract Widget getLabel();
	public abstract Panel getPanel();
	public void addTo(TabPanel tp) {
		Panel panel = getPanel();
		tp.add(panel, getLabel());
		int index = tp.getWidgetIndex(panel);
		BeforeSelectionHandler<Integer> handler = getSelectionHandler(index);
		if (handler!=null) tp.addBeforeSelectionHandler(handler);
	}
	protected BeforeSelectionHandler<Integer> getSelectionHandler(int index) {
		return null;
	}
}
